/**
 * 
 */
package leetCode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhong
 *
 */
public class GoatLatin {
	Set<Character> vol = new HashSet<>();

	public String toGoatLatin(String S) {
		vol.add('a');
		vol.add('e');
		vol.add('i');
		vol.add('o');
		vol.add('u');

		StringBuilder sBuilder = new StringBuilder();
		String[] words = S.split(" ");
		StringBuilder aBuilder = new StringBuilder("a");
		for (int i = 0; i < words.length; i++) {
			String word = words[i];
			if (vol.contains(Character.toLowerCase(word.charAt(0)))) {
				sBuilder.append(word);
			} else {
				sBuilder.append(word.substring(1));
				sBuilder.append(word.charAt(0));
			}
			sBuilder.append("ma");
			sBuilder.append(aBuilder);

			aBuilder.append('a');
			if (i != words.length - 1) {
				sBuilder.append(' ');
			}
		}
		return sBuilder.toString();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String S = "The quick brown fox jumped over the lazy dog";
		System.out.println(new GoatLatin().toGoatLatin(S));
	}

}
